package com.change.study.action.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.change.study.data.entity.User;
import com.change.study.data.service.UserService;


@RestController
@RequestMapping(value="api")
public class UserAction {

	
	@Autowired
	UserService userService;

	@RequestMapping(value = "login", method = RequestMethod.GET)
	public  User login(String username, String password,
			String macaddress, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		User uer = userService.login(username, password, macaddress);
		if (uer == null) {
			uer = new User();
			uer.setId(-1l);
		}
		return uer;
	}
	
	@RequestMapping(value = "login1", method = RequestMethod.GET)
	public  @ResponseBody User login1(String username, String password,
			String macaddress, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		User uer = userService.login(username, password, macaddress);
		if (uer == null) {
			uer = new User();
			uer.setId(-1l);
		}
		return uer;
	}
}
